<?php
include_once("../controller/urgencia_controller_class.php");
include_once("../controller/ocorrencia_controller_class.php");

$objUrgencia = new UrgenciaController();
$listUrg = $objUrgencia->selecionar();

$id = $_GET['id'];

$objOcorrencia = new OcorrenciaController();

$ocorrencia = $objOcorrencia->selecionarPorId($id)->getUrgencia();

if(isset($_POST['salvar'])){
    $urgencia = $_POST['txtUrgencia'];
    
    if($urgencia == 0){
        echo "<script>alert('Selecione a Urgencia')</script>";
    }else{
        if($objOcorrencia->alterarUrgencia($id, $urgencia)){
            echo "<script>alert('Cadastrado com Sucesso')</script>";
            echo "<script>opener.location.reload()</script>";
            echo "<script>window.self.close()</script>";
        }else{
            echo "<script>alert('Erro')</script>";
        }
    }
}

?>
<!DOCTYPE html>
<html lang="en" class="no-js">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <title>::: SOS UNITAU -- Sistema de ordem de serviço</title>

        <link rel="shortcut icon" href="img/logo.jpg">
        <link rel="stylesheet" type="text/css" href="css/normalize.css" />
        <link rel="stylesheet" type="text/css" href="css/demo.css" />
        <link rel="stylesheet" type="text/css" href="css/icons.css" />
        <link rel="stylesheet" type="text/css" href="css/style2.css" />
        <link rel="stylesheet" type="text/css" href="css/StylePage.css" />
        <link rel="stylesheet" type="text/css" href="css/default.css" />
        <link rel="stylesheet" type="text/css" href="css/component.css" />
        <script src="js/jquery.maskedinput-1.3.min.js"></script>

        <script type="text/javascript"><!-- PARA NAO CONFLITAR -->

            var $JQuery = jQuery.noConflict();
        </script>

        <script>



        </script>


    </head>
    <body>
        <form name="alterarConfig" id="alterarConfig" method="post" enctype="multipart/form-data" action="" class="style-form">

            <fieldset style="width:30px;">
                <legend>Alterar Configuração de urgência: </legend>
                <table width="800px" class="table-form">
                    <tr>
                        <td> 
                            <label for="txtUrgencia"> Urgência: </label> 
                        </td>
                        <td> 
                            <select name="txtUrgencia" id="txtUrgencia"> 
                                <option value="o">Selecione</option>
                                <?php foreach ($listUrg as $urg) { ?>
                                    <option 
                                        <?php if ($ocorrencia->getId() == $urg->getId()) {
                                            echo "selected";
                                        } ?> value="<?= $urg->getId() ?>">
                                    <?= $urg->getNome() ?></option>
<?php } ?>

                            </select>
                        </td>
                    </tr>


                </table>
                <input type="hidden" name="id" value="<?= @$id ?>" />
                <input type="submit" value="Salvar" name="salvar" style="display:inline-block; margin-left:50%; margin-top:3%;" class="botao"  /><input type="button" value="Cancelar" style="margin-left:5%;" onClick="javascript:c = window.confirm('Deseja Realmente cancelar?');
                        if (c == true) {
                            self.close();
                        } else {
                        }" class="botao" />    
            </fieldset>

        </form>


    </body>
</html>